package com.lintf.distributed.transaction.inventory.rpc;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lintf.distributed.transaction.api.InventoryRPCService;
import com.lintf.distributed.transaction.dto.InventoryGetDTO;
import com.lintf.distributed.transaction.inventory.entity.Inventory;
import com.lintf.distributed.transaction.inventory.service.InventoryService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

/**
 * @ author lintf
 * @ system Mac
 * @ data 2025/7/9
 * @ package_name com.lintf.distributed.transaction.inventory.rpc
 * @ project_name distributed-transaction
 * @ desc
 */

@RequiredArgsConstructor
@DubboService(interfaceClass = InventoryRPCService.class, version = InventoryRPCService.RPC_VERSION)
public class InventoryRPCServiceImpl implements InventoryRPCService {

    private final InventoryService inventoryService;

    @Override
    public InventoryGetDTO getInventoryDetail(Long productId) {
        Inventory inventory = inventoryService.getOne(new LambdaQueryWrapper<Inventory>().eq(Inventory::getProductId, productId));
        InventoryGetDTO dto = new InventoryGetDTO();
        BeanUtils.copyProperties(inventory, dto);
        return dto;
    }
}
